home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12651 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: newsroom.hitc.com!kfreeman
  2. From: kfreeman@mandrake.HITC.COM (Keith Freeman)
  3. Newsgroups: comp.lang.c++,comp.os.linux.development.apps,comp.os.linux.misc
  4. Subject: Re: Are str* functions okay in C++?
  5. Date: 20 Mar 1996 17:24:32 GMT
  6. Organization: Hughes Team (EOSDIS)
  7. Message-ID: <KFREEMAN.96Mar20122432@mandrake.HITC.COM>
  8. References: <4hpvi0$gt6@news.platinum.com> <Do54G9.4Ly.0.server@indra.com>
  9.     <Do61wK.IEG@beaver.cs.washington.edu> <3146A6B6.6455D253@indra.com>
  10. NNTP-Posting-Host: mandrake.hitc.com
  11. In-reply-to: Bear Giles's message of Wed, 13 Mar 1996 10:43:02 GMT
  12.  
  13. In article <3146A6B6.6455D253@indra.com> Bear Giles <bear@indra.com> writes:
  14. > Randy Chapman wrote:
  15. > > Bear Giles (bear@) wrote:
  16. > > : Also, another useful technique for this type of code is:
  17. > > 
  18. > > : void procedure (argument...)
  19. > > :    {
  20. > > :    static char * buffer = 0;
  21. > > 
  22. > > :    if (buffer == 0)
  23. > > :        buffer = malloc (2048);  /* or any _large_ number */ 
  24. > > :    ...
  25. > > However, it limits you to non-multithreaded programs.  Its little things
  26. > > like this that make trying to use existing code in a multithreaded
  27. > > environment really hard sometimes =(
  28.  
  29. And, this can cause very subtle problems in single-threaded programs.
  30. If your function returns a pointer to the buffer (like the standard
  31. library function strtok()), many users will naively:
  32.  
  33.   1) call it several times, storing each returned (identical!)
  34.      pointer somewhere;
  35.  
  36.   2) place more than one call in the argument list passed to another
  37.      function (all point to the same result, but which one?)
  38.  
  39. keith freeman
  40. kfreeman@eos.hitc.com
  41.  
  42.  
  43.